<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_themeGridUnique"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<span id="show"></span>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";

    var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
       "with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
       " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

    var dataUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图";
    var map = new mapboxgl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [host + '/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?prjCoordSys='+encodeURIComponent('{"epsgCode":3857}')+'&z={z}&x={x}&y={y}'],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        },
        center: [117, 40],
        zoom: 6
    });
    map.addControl(new mapboxgl.NavigationControl(), 'top-left');
    map.addControl(new mapboxgl.supermap.LogoControl({ link: "https://iclient.supermap.io" }), 'bottom-right');

    function setItems() {
        var items = [],
            color0 = new mapboxgl.supermap.ServerColor(198, 244, 240),
            color1 = new mapboxgl.supermap.ServerColor(176, 244, 188),
            color2 = new mapboxgl.supermap.ServerColor(218, 251, 178),
            color3 = new mapboxgl.supermap.ServerColor(220, 236, 145),
            color4 = new mapboxgl.supermap.ServerColor(96, 198, 66),
            color5 = new mapboxgl.supermap.ServerColor(20, 142, 53),
            color6 = new mapboxgl.supermap.ServerColor(85, 144, 55),
            color7 = new mapboxgl.supermap.ServerColor(171, 168, 38),
            color8 = new mapboxgl.supermap.ServerColor(235, 165, 9),
            color9 = new mapboxgl.supermap.ServerColor(203, 89, 2),
            color10 = new mapboxgl.supermap.ServerColor(157, 25, 1),
            color11 = new mapboxgl.supermap.ServerColor(118, 15, 3),
            color12 = new mapboxgl.supermap.ServerColor(112, 32, 7),
            color13 = new mapboxgl.supermap.ServerColor(106, 45, 12),
            color14 = new mapboxgl.supermap.ServerColor(129, 80, 50),
            color15 = new mapboxgl.supermap.ServerColor(160, 154, 146);

        for (var i = -4; i < 2197; i++) {
            var num = parseInt(i / 135);
            var item = new mapboxgl.supermap.ThemeGridUniqueItem();
            item.caption = 1;
            item.unique = i;
            item.visible = true;
            switch (num) {
                case 0:
                    item.color = color0;
                    break;
                case 1:
                    item.color = color1;
                    break;
                case 2:
                    item.color = color2;
                    break;
                case 3:
                    item.color = color3;
                    break;
                case 4:
                    item.color = color4;
                    break;
                case 5:
                    item.color = color5;
                    break;
                case 6:
                    item.color = color6;
                    break;
                case 7:
                    item.color = color7;
                    break;
                case 8:
                    item.color = color8;
                    break;
                case 9:
                    item.color = color9;
                    break;
                case 10:
                    item.color = color10;
                    break;
                case 11:
                    item.color = color11;
                    break;
                case 12:
                    item.color = color12;
                    break;
                case 13:
                    item.color = color13;
                    break;
                case 14:
                    item.color = color14;
                    break;
                case 15:
                    item.color = color15;
                    break;
                default:
                    item.color = color0;
                    break;
            }
            items.push(item);
        }
        return items;
    }


    function createTheme() {

        themeGridUnique = new mapboxgl.supermap.ThemeGridUnique({
            defaultcolor: new mapboxgl.supermap.ServerColor(0, 0, 0),
            items: setItems()
        });

        themeParameters = new mapboxgl.supermap.ThemeParameters({
            datasetNames: ["JingjinTerrain"],
            dataSourceNames: ["Jingjin"],
            themes: [themeGridUnique]
        });

        new mapboxgl.supermap.ThemeService(dataUrl).getThemeInfo(themeParameters).then(function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                map.addSource("theme", {
                    "type": 'raster',
                    "tiles": [host + '/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}&noWrap=true&transparent=true&cacheEnabled=false&layersID=' + result.newResourceID],
                    "tileSize": 256,
                });

                map.addLayer({
                    "id": "themeLayer",
                    "type": "raster",
                    "source": "theme",
                });
            }
        })
    }

    map.on('load', function () {

        createTheme();
    });

</script>

</body>
</html>